package com.itheima.sys.mapper;

import com.itheima.sys.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色表  Mapper 接口
 * </p>
 *
 * @author itheima
 * @since 2020-12-13
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 根据企业员工ID，企业ID 查询员工对应角色列表
     * @param companyUserId
     * @param companyId
     * @return
     */
    @Select("select r.* from (SELECT\n" +
            "\t*\n" +
            "FROM\n" +
            "\t`company_user` cu\n" +
            "WHERE\n" +
            "\tcu.company_id = #{companyId}\n" +
            "AND cu.id = #{companyUserId}) temp\n" +
            "\n" +
            "\n" +
            "INNER JOIN company_user_role cur ON cur.company_user_id = temp.id\n" +
            "INNER JOIN sys_role r ON cur.role_id = r.id")
    List<SysRole> queryRoles(@Param("companyUserId") Long companyUserId, @Param("companyId") Long companyId);
}
